<template>
  <div class="func-comp-form">

    <ComponentGlobalSettingForm :id="id" :compConfigData="compConfigData"></ComponentGlobalSettingForm>

    <Tabs name="main_tabs" size="small" v-model="mainTabsValue">
      <TabPane name="main_tab" tab="main_tabs" label="主配置">

        <Tabs name="main_tabs_child" size="small">
          <TabPane tab="main_tabs_child" label="基础配置">
            <Collapse value="0">
              <Panel>
                常规配置
                <div slot="content">
                  <Form :label-width="100">

                    <FormItem label="南丁格尔图">
                      <Select :transfer="true" size="small" v-model="chartOption.pie.roseType" placement="bottom-end">
                        <Option v-for="item in $PnChartDict.pieRoseTypes" :value="item.value" :label="item.label" :key="item.value">
                          <span>{{ item.label }}</span>
                          <p style="color: #808695;">{{item.remark}}</p>
                        </Option>
                      </Select>
                    </FormItem>

                    <FormItemPanel title="系列项统一样式">
                      <FormItem label="边框宽度">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.itemStyle.borderWidth"></InputNumber>
                      </FormItem>
                      <FormItem label="边框颜色">
                        <PnColorPicker size="small" v-model="chartOption.pie.itemStyle.borderColor" alpha recommend/>
                      </FormItem>
                      <FormItem label="阴影宽度">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.itemStyle.shadowBlur"></InputNumber>
                      </FormItem>
                      <FormItem label="阴影颜色">
                        <PnColorPicker size="small" v-model="chartOption.pie.itemStyle.shadowColor" alpha recommend/>
                      </FormItem>
                    </FormItemPanel>

                  </Form>
                </div>
              </Panel>
              <Panel>
                自定义色系
                <div slot="content">
                  <Form :label-width="100">
                    <Button class="float-right" size="small" type="primary" @click="addColor"><Icon type="md-add" /> 新增色值</Button>
                    <div class="clearfix"></div>
                    <div class="m-b-10px"></div>

                    <FormItem :label="'色值'+(index+1)" v-for="(c, index) in chartOption.pie.color" :key="index">
                      <PnColorPicker size="small" v-model="chartOption.pie.color[index]" alpha recommend/>
                      <a href="javascript:;" class="m-l-5px" style="color: #757575;" @click.stop="deleteColor(index)"><Icon type="md-trash" /></a>
                    </FormItem>

                  </Form>
                </div>
              </Panel>
              <Panel>
                径向轴
                <div slot="content">
                  <Form :label-width="100">
                    <Alert type="info">可以将内半径设大显示成圆环图</Alert>
                    <FormItem label="内半径">
                      <Input size="small" v-model="chartOption.pie.radius[0]" placeholder=""/>
                    </FormItem>
                    <FormItem label="外半径">
                      <Input size="small" v-model="chartOption.pie.radius[1]" placeholder=""/>
                    </FormItem>
                  </Form>
                </div>
              </Panel>
              <Panel>
                值标签
                <div slot="content">
                  <Form :label-width="100">

                    <FormItem label="显示">
                      <i-switch v-model="chartOption.pie.label.show">
                        <span slot="open"></span>
                        <span slot="close"></span>
                      </i-switch>
                    </FormItem>
                    <FormItem label="位置">
                      <Select :transfer="true" size="small" v-model="chartOption.pie.label.position">
                        <Option v-for="item in $PnChartDict.pieLabelPositions" :value="item.value" :key="item.value">{{ item.label }}</Option>
                      </Select>
                    </FormItem>
                    <FormItem label="格式化">
                      <a href="https://echarts.apache.org/zh/option.html#series-pie.label.formatter" target="_blank">参考文档</a>
                      <Input size="small" v-model="chartOption.pie.label.formatter" placeholder=""/>
                    </FormItem>
                    <FormItem label="字体颜色">
                      <PnColorPicker size="small" v-model="chartOption.pie.label.color" alpha recommend/>
                      <Checkbox v-model="chartOption.pie.label.autoColor">是否同步设置为系列色</Checkbox>
                    </FormItem>
                    <FormItem label="字体大小">
                      <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.label.fontSize"></InputNumber>
                    </FormItem>
                    <FormItem label="背景色">
                      <PnColorPicker size="small" v-model="chartOption.pie.label.backgroundColor" alpha recommend/>
                    </FormItem>
                    <FormItem label="内边距">
                      <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.label.padding"></InputNumber>
                    </FormItem>
                    <FormItem label="边框宽度">
                      <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.label.borderWidth"></InputNumber>
                    </FormItem>
                    <FormItem label="边框颜色">
                      <PnColorPicker size="small" v-model="chartOption.pie.label.borderColor" alpha recommend/>
                    </FormItem>
                    <FormItem label="边框圆角">
                      <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.label.borderRadius"></InputNumber>
                    </FormItem>
                    <FormItemPanel title="标签视觉引导线样式">
                      <FormItem label="显示">
                        <i-switch v-model="chartOption.pie.labelLine.show">
                          <span slot="open"></span>
                          <span slot="close"></span>
                        </i-switch>
                      </FormItem>
                      <FormItem label="线1长度">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.labelLine.length"></InputNumber>
                      </FormItem>
                      <FormItem label="线2长度">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.labelLine.length2"></InputNumber>
                      </FormItem>
                      <FormItem label="线宽">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.pie.labelLine.lineStyle.width"></InputNumber>
                      </FormItem>
                    </FormItemPanel>

                  </Form>
                </div>
              </Panel>
              <Panel>
                提示框
                <div slot="content">
                  <Form :label-width="80">
                    <FormItem label="显示">
                      <i-switch v-model="chartOption.tooltip.show">
                        <span slot="open"></span>
                        <span slot="close"></span>
                      </i-switch>
                    </FormItem>
                    <FormItem label="触发类型">
                      <Select :transfer="true" size="small" v-model="chartOption.tooltip.trigger">
                        <Option v-for="item in $PnChartDict.triggers" :value="item.value" :key="item.value">{{ item.label }}</Option>
                      </Select>
                    </FormItem>
                    <FormItem label="触发动作">
                      <Select :transfer="true" size="small" v-model="chartOption.tooltip.triggerOn">
                        <Option v-for="item in $PnChartDict.triggerOns" :value="item.value" :key="item.value">{{ item.label }}</Option>
                      </Select>
                    </FormItem>
                    <FormItemPanel title="背景框样式">
                      <FormItem label="背景色">
                        <PnColorPicker size="small" v-model="chartOption.tooltip.backgroundColor" alpha recommend/>
                      </FormItem>
                      <FormItem label="内边距">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.tooltip.padding"></InputNumber>
                      </FormItem>
                      <FormItem label="边框宽度">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.tooltip.borderWidth"></InputNumber>
                      </FormItem>
                      <FormItem label="边框颜色">
                        <PnColorPicker size="small" v-model="chartOption.tooltip.borderColor" alpha recommend/>
                      </FormItem>
                    </FormItemPanel>
                    <FormItemPanel title="文本样式">
                      <FormItem label="颜色">
                        <PnColorPicker size="small" v-model="chartOption.tooltip.textStyle.color" alpha recommend/>
                      </FormItem>
                      <FormItem label="字体大小">
                        <InputNumber size="small" :max="1000" :min="0" v-model="chartOption.tooltip.textStyle.fontSize"></InputNumber>
                      </FormItem>
                    </FormItemPanel>
                  </Form>
                </div>
              </Panel>
              <Panel>
                图例
                <div slot="content">
                  <Form :label-width="80">
                    <FormItem label="显示">
                      <i-switch v-model="chartOption.legend.show">
                        <span slot="open"></span>
                        <span slot="close"></span>
                      </i-switch>
                    </FormItem>
                    <FormItem label="位置">
                      <Select :transfer="true" size="small" v-model="chartOption.legend.position">
                        <Option v-for="item in $PnChartDict.legendPositions" :value="item.value" :key="item.value">{{ item.label }}</Option>
                      </Select>
                    </FormItem>
                    <FormItem label="布局朝向">
                      <Select :transfer="true" size="small" v-model="chartOption.legend.orient">
                        <Option v-for="item in $PnChartDict.orients" :value="item.value" :key="item.value">{{ item.label }}</Option>
                      </Select>
                    </FormItem>
                    <FormItem label="图标形状">
                      <Select :transfer="true" size="small" v-model="chartOption.legend.icon">
                        <Option v-for="item in $PnChartDict.symbols" :value="item.value" :key="item.value">{{ item.label }}</Option>
                      </Select>
                    </FormItem>
                    <FormItemPanel title="文本样式">
                      <FormItem label="颜色">
                        <PnColorPicker size="small" v-model="chartOption.legend.textStyle.color" alpha recommend/>
                      </FormItem>
                      <FormItem label="字体大小">
                        <InputNumber size="small" :max="1000" :min="1" v-model="chartOption.legend.textStyle.fontSize"></InputNumber>
                      </FormItem>
                    </FormItemPanel>
                  </Form>
                </div>
              </Panel>
              <Panel v-if="chartOption.title">
                标题
                <ShowToggle class="float-right" v-model="chartOption.title.show"></ShowToggle>
                <div slot="content">
                  <EchartsTitleConfigForm v-model="chartOption.title"></EchartsTitleConfigForm>
                </div>
              </Panel>
              <Panel>
                其他
                <div slot="content">
                  <EchartsOtherConfigForm v-model="compConfigData"></EchartsOtherConfigForm>
                </div>
              </Panel>
            </Collapse>
          </TabPane>
          <TabPane tab="main_tabs_child" label="系列映射">
            <Button class="float-right" size="small" type="primary" @click="addSeries"><Icon type="md-add" /> 新增映射</Button>
            <div class="clearfix"></div>
            <div class="m-b-10px"></div>

            <draggable tag="Collapse" :component-data="{attrs: {accordion: true}}" :list="chartOption.series" handle=".ivu-collapse-header">
              <Panel :name="$PnUtil.uuid()" v-for="(row, index) in chartOption.series" :key="index">
                {{row.name ? row.name : '系列' + (index + 1)}}
                <a href="javascript:;" class="float-right m-r-5px" style="color: #757575;" @click.stop="deleteSeries(index)"><Icon type="md-trash" /></a>
                <div slot="content">
                  <Form :label-width="100">
                    <FormItem label="类目名称">
                      <Input size="small" v-model="row.name" placeholder=""/>
                    </FormItem>
                    <FormItem label="默认强调">
                      <i-switch v-model="row.selected">
                        <span slot="open"></span>
                        <span slot="close"></span>
                      </i-switch>
                    </FormItem>
                    <FormItem label="颜色">
                      <PnColorPicker size="small" v-model="row.itemStyle.color" alpha recommend/>
                    </FormItem>
                    <FormItem label="边框宽度">
                      <InputNumber size="small" :max="1000" :min="0" v-model="row.itemStyle.borderWidth"></InputNumber>
                    </FormItem>
                    <FormItem label="边框颜色">
                      <PnColorPicker size="small" v-model="row.itemStyle.borderColor" alpha recommend/>
                    </FormItem>

                  </Form>
                </div>
              </Panel>
            </draggable>
          </TabPane>
        </Tabs>

      </TabPane>
      <TabPane name="extend_tab" tab="main_tabs" label="扩展配置">
        <Container v-if="mainTabsValue == 'extend_tab'">
          <CustomOptionDocument :componentId="id"></CustomOptionDocument>
          <CodeEditor v-model="customOption" mode="json"></CodeEditor>
          <EchartsSpreadingCodeForm v-model="echartsSpreadingCode"></EchartsSpreadingCodeForm>
        </Container>
      </TabPane>
      <TabPane name="datasource_tab" tab="main_tabs" label="数据源">
        <DatasourceState v-if="mainTabsValue == 'datasource_tab'" targetComp="BasePieChart"></DatasourceState>
      </TabPane>
      <TabPane name="interaction_tab" tab="main_tabs" label="交互">
        <Container v-if="mainTabsValue == 'interaction_tab'">
          <InteractionReceive></InteractionReceive>
          <CustomJsDocument></CustomJsDocument>
          <FormItemPanel title="初始化运行脚本">
            <CodeEditor v-model="customGlobalJsCode"></CodeEditor>
          </FormItemPanel>

          <FormItemPanel title="数据项点击时运行">
            <InteractionSender :interactionKey="'itemClick'"></InteractionSender>
            <Alert style="padding: 5px;">此脚本中，使用_this指向当前组件vm实例，通过params可获取点击项数据</Alert>
            <CodeEditor v-model="dataItemClickJsCode"></CodeEditor>
          </FormItemPanel>
        </Container>
      </TabPane>
    </Tabs>
  </div>
</template>

<script>

  import FuncCompFormMixin from '@/mixin/FuncCompFormMixin'

  import { createHelpers } from 'vuex-map-fields';
  import BasePieChart from "./BasePieChart";

  const { mapFields } = createHelpers({
    getterType: 'designer/getLayoutItem',
    mutationType: 'designer/updateLayoutItem',
  });

  export default {
    name: 'BasePieChartForm',
    mixins: [FuncCompFormMixin],
    data() {
      return {

      }
    },
    mounted() {

    },
    methods: {
      addColor() {
        this.chartOption.pie.color.push('')
      },
      deleteColor (index) {
        this.chartOption.pie.color.splice(index, 1)
      },
      addSeries () {
        this.chartOption.series.push(BasePieChart.buildSeriesObj())
      },
      deleteSeries (index) {
        this.chartOption.series.splice(index, 1)
      }
    },
    computed: {
      ...mapFields({

        chartOption: 'component.compConfigData.chartOption'

      })
    }
  }
</script>

<style scoped>

</style>
